package com.hbnu.tools;

import java.util.Scanner;

public class ScannerTool {
    private final static Scanner scanner=new Scanner(System.in);
    //去空白
    public static String nextLine(){
        return scanner.nextLine().trim();
    }
    public static String nextLine(String s){
        while (true) {
            PrintTool.print(s);
            String str = nextLine();
            if(str.isEmpty()) continue;
            return str;
        }
    }
    public static int nextInt(String s){
        int result;
        while (true) {
            PrintTool.print(s);
            String str = nextLine();
            if(str.isEmpty()) return -1;
            try {
                result=Integer.parseInt(str);
            }catch (Exception exception){
                PrintTool.println("请输入数字！");
                continue;
            }
            if(result<0){
                PrintTool.println("请输入大于零的整字！");
                continue;
            }
            return result;
        }
    }
    public static String nextLine(StringBuilder tip){
        return nextLine(tip.toString());
    }
}
